import { useState } from 'react';

/*
 * @Author       : 魏威 <1209562577@qq.com>
 * @Date         : 2021-08-25 19:22 周3
 * @Description  : useArray hook
 */

export const useArray = <T>(array: T[]) => {
  const [value, setValue] = useState(array);
  return {
    value,
    setValue,
    add: (item: T) => setValue([...value, item]),
    removeIndex: (index: number) => {
      const copy = [...value];
      copy.splice(index, 1);
      setValue(copy);
    }
  };
};
